/*
 * alloc memory method is malloc().
 *
 * Copyright (C) 2014 Ingenic Semiconductor Co.,Ltd
 * Author: Aeolus <weiqing.yan@ingenic.com>
 */

#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/fcntl.h>
#include <sys/mman.h>

#include <imp/imp_log.h>

#include "alloc_manager.h"
#include "alloc_common.h"
#ifdef DMALLOC
#include <imp/dmalloc.h>
#endif
#define TAG "Malloc Method"

//#define MAX_MALLOC_SIZE (32 * 1024 * 1024)

int alloc_malloc_init(Alloc *alloc)
{
	if(!(alloc)) {
		IMP_LOG_ERR(TAG, "%s function param is NULL\n", __func__);
		return -1;
	}

	/*sprintf(alloc->mem_alloc.method, "malloc");*/

	alloc->mem_alloc.vaddr = (uint32_t)valloc(MAX_MALLOC_SIZE);
	if(!(alloc->mem_alloc.vaddr)) {
		IMP_LOG_ERR(TAG, "pmem mmap failed\n");
		return -1;
	}
	alloc->mem_alloc.length = MAX_MALLOC_SIZE;
	alloc->mem_alloc.paddr = 0;

	IMP_LOG_DBG(TAG, "alloc->mem_alloc.method = %s\n \
			alloc->mem_alloc.vaddr = 0x%08x\n \
			alloc->mem_alloc.paddr = 0x%08x\n \
			alloc->mem_alloc.length = %d\n",
			alloc->mem_alloc.method,
			alloc->mem_alloc.vaddr,
			alloc->mem_alloc.paddr,
			alloc->mem_alloc.length);

	return 0;
}

uint32_t alloc_malloc_get_paddr(uint32_t vaddr)
{
	IMP_LOG_ERR(TAG, "alloc_malloc_get_paddr is not support\n");
	return 0;
}
